<template>
	<hyb-page :title="$store.state.base.show_base.shifu_bie_ming + '中心'" :leading="false">
		<!-- 请开始您的开发 ~ -->
		<template v-slot:body>
			<view>

				<view class="gui-list" :style="{'background':base.qjcolor}">
					<view style="height: 40rpx;"></view>
					<view class="gui-flex gui-justify-content-end gui-padding-x">
						<view @tap="location()" class="gui-color-white"><text class="gui-icons">&#xe61c;</text>
						</view>
					</view>
					<view class="gui-padding-middle gui-list-items" style="height: 145rpx;">
						<!-- #ifdef MP -->
						<button class="avatar-wrapper" style="width: 120rpx;height: 120rpx;border-radius: 50%;"
							open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar">
							<image style="width: 120rpx;height: 120rpx;border-radius: 50%;"
								:src="info.y_thumb?info.y_thumb:base.erweima" mode="scaleToFill">
							</image>
						</button>
						<!-- #endif -->

						<!-- #ifndef MP -->
						<image style="width: 120rpx;height: 120rpx;border-radius: 50%;"
							:src="info.y_thumb?info.y_thumb:base.erweima" mode="scaleToFill">
						</image>
						<!-- #endif -->


						<view class="gui-list-body">
							<view class="gui-list-title">
								<text class="gui-list-title-text gui-color-white">{{info.y_name}}</text>
								<!-- <navigator url="/hyb_o2o/shouce/index/index?type=yg">
									<text class="gui-icons gui-block gui-text gui-padding-x"
										style="font-size: 30rpx;color:#ffffff;">入驻须知&#xe601;</text>
								</navigator> -->

							</view>



							<view class="gui-color-white gui-text-small gui-margin-top2"
								v-if="info.y_endtime && $store.state.base.shifu_huiyuan">
								会员到期:{{info.y_endtime}}
							</view>
						</view>
					</view>
				</view>
				<!-- #ifdef MP -->
				<official-account v-if="!$store.state.userinfo.openid"></official-account>
				<!-- #endif -->


				<!-- <view style="height: 20rpx;" class="gui-bg-gray"></view> -->
				<view class="gui-border-radius-large gui-margin-top-middle gui-bg-white gui-margin-x-middle">
					<navigator v-if="$store.state.base.shifu_huiyuan && $store.state.base.uniacid != 15"
						url="/hyb_o2o/jishi/huiyuan/huiyuan">
						<view class="gui-list  gui-border-b">
							<view class="gui-padding-middle gui-list-items">
								<text class="gui-list-icon gui-icons " style="font-size: 38rpx;">&#xe612;</text>
								<view class="gui-list-body">
									<view class="gui-list-title">
										<view class="gui-flex gui-align-items-center">
											<text class="gui-list-title-text">购买会员</text>
										</view>

									</view>
								</view>
								<text class="gui-list-arrow-right gui-icons gui-color-gray">&#xe601;</text>
							</view>
						</view>
					</navigator>
					<navigator v-if="base.yg_set.shi_fou_qd" :url="base.zdycd_lj[2]+info.y_id+'&y_expire=' + info.y_expire">
						<view class="gui-list">
							<view class="gui-padding-middle gui-list-items gui-border-b">
								<text class="gui-list-icon gui-icons "
									style="font-size: 40rpx;color: #c2c2c2;">&#xe608;</text>
								<view class="gui-list-body">
									<view class="gui-list-title">
										<view class="gui-flex gui-align-items-center">
											<text class="gui-list-title-text">需求大厅</text>
										</view>

									</view>
								</view>
								<text class="gui-list-arrow-right gui-icons gui-color-gray">&#xe601;</text>
							</view>
						</view>
					</navigator>
					<navigator :url="base.zdycd_lj[3]+info.y_id">
						<view class="gui-list  gui-border-b">
							<view class="gui-padding-middle gui-list-items">
								<text class="gui-list-icon gui-icons "
									style="font-size: 40rpx;color: #c2c2c2;">&#xe62f;</text>
								<view class="gui-list-body">
									<view class="gui-list-title">
										<view class="gui-flex gui-align-items-center">
											<text class="gui-list-title-text">{{base.zdycd[3]}}</text>
										</view>

									</view>
								</view>
								<text class="gui-list-arrow-right gui-icons gui-color-gray">&#xe601;</text>
							</view>
						</view>
					</navigator>
					<navigator url="/hyb_o2o/jishi/ruzhu/ruzhu?tz_type=xg">
						<view class="gui-list  gui-border-b">
							<view class="gui-padding-middle gui-list-items">
								<text class="gui-list-icon gui-icons "
									style="font-size: 40rpx;color: #c2c2c2;">&#xe613;</text>
								<view class="gui-list-body">
									<view class="gui-list-title">
										<view class="gui-flex gui-align-items-center">
											<text class="gui-list-title-text">资料修改</text>
										</view>

									</view>
								</view>
								<text class="gui-list-arrow-right gui-icons gui-color-gray">&#xe601;</text>
							</view>
						</view>
					</navigator>


					<!-- <navigator url="/hyb_o2o/inner/pages/balance/balance?tag=yg" v-if="$store.state.base.yu_e">
						<view class="gui-list gui-border-b">
							<view class="gui-padding-middle gui-list-items">
								<text class="gui-list-icon gui-icons  "
									style="font-size: 40rpx;color: #c2c2c2;">&#xe614;</text>
								<view class="gui-list-body">
									<view class="gui-list-title">
										<view class="gui-flex gui-align-items-center">
											<text class="gui-list-title-text">资金明细</text>
										</view>

									</view>
								</view>
								<text class="gui-list-arrow-right gui-icons gui-color-gray">&#xe601;</text>
							</view>
						</view>
					</navigator> -->
					<!-- <navigator url="/hyb_o2o/fenyong/fenyong?tag=yg" v-if="$store.state.base.yu_e">
						<view class="gui-list gui-border-b">
							<view class="gui-padding-middle gui-list-items">
								<text class="gui-list-icon gui-icons  "
									style="font-size: 40rpx;color: #c2c2c2;">&#xe614;</text>
								<view class="gui-list-body">
									<view class="gui-list-title">
										<view class="gui-flex gui-align-items-center">
											<text class="gui-list-title-text">分佣明细</text>
										</view>

									</view>
								</view>
								<text class="gui-list-arrow-right gui-icons gui-color-gray">&#xe601;</text>
							</view>
						</view>
					</navigator> -->


				</view>

				<view class="gui-margin-top-middle gui-margin-x-middle gui-bg-white gui-border-radius-large">

					<view class="gui-list gui-border-b" v-if="$store.state.base.yu_e">
						<view class="gui-padding-middle gui-list-items">
							<text class="gui-list-icon gui-icons "
								style="font-size: 40rpx;color: #c2c2c2;">&#xe6d1;</text>
							<view class="gui-list-body">
								<view class="gui-list-title">
									<view class="gui-flex gui-align-items-center">
										<text class="gui-list-title-text">是否接单</text>
									</view>

								</view>
							</view>
							<switch :color="$store.state.base.qjcolor" style="transform:scale(0.7)"
								:checked="info.jd_tongzhi==1?true:false" @change="jdChange" color="#008AFF" />
						</view>
					</view>
					<navigator>
						<view v-if="base.show_base.bao_zheng_jin  > 0 || info.baozhengjin > 0"
							class="gui-padding-middle gui-list-items  gui-border-b" @tap="bzj">
							<text class="gui-list-icon gui-icons "
								style="font-size: 40rpx;color: #c2c2c2;">&#xe687;</text>
							<view class="gui-list-body ">
								<view class="gui-list-title">
									<view class="gui-flex gui-align-items-center">
										<text class="gui-list-title-text">保证金</text>
										<text v-if="info.baozhengjin > 0"
											class="gui-text-small  gui-margin-x gui-color-gray">￥
											{{info.baozhengjin}}</text>
										<text v-else class="gui-text-small  gui-margin-x gui-color-gray">￥0.00</text>


									</view>

								</view>
							</view>
							<text class="gui-list-arrow-right gui-icons gui-color-gray">&#xe601;</text>
						</view>
					</navigator>
					<view class="gui-margin-top-middle gui-margin-x-middle gui-bg-white gui-border-radius-large">
						<view class="gui-list ">
							<view class="gui-list-items   gui-padding-y-middle gui-border-b">
								<text class="gui-list-icon gui-icons  "
									style="font-size: 37rpx;color: #c2c2c2;">&#xe612;</text>
								<view class="gui-list-body ">
									<view class="gui-list-title">
										<view class="gui-flex gui-align-items-center">
											<text class="gui-list-title-text">我的钱包</text>
											<text
												class="gui-text-small  gui-margin-x gui-color-gray">￥{{info.y_money}}</text>
										</view>

									</view>
								</view>
								<button type="default" @tap="ti_xian()" :style="{'background':base.qjcolor}"
									style="transform:scale(0.9)" class="gui-button gui-noborder">
									<text class="gui-color-white gui-button-text gui-text-small">提现</text>
								</button>
							</view>
						</view>
					</view>





				</view>
				<view v-if="$store.state.base.yg_fx"
					class="gui-margin-top-middle gui-margin-x-middle gui-bg-white gui-border-radius-large">
				</view>
			</view>
			<view style="height: 1rpx;"></view>
			<hyb-bzj ref="bzj"></hyb-bzj>
			<gui-modal ref="popup" :customClass="['gui-bg-white', 'gui-dark-bg-level-3', 'gui-border-radius']"
				title="注销验证码">
				<template v-slot:content>
					<view class="gui-flex gui-space-between gui-align-items-center gui-padding-x">
						<view class="gui-margin gui-bg-gray gui-border-radius" style="padding: 16rpx 20rpx;">
							<input v-model="code" type="number" placeholder="请输入验证码" />
						</view>
						<view v-if="time==0" class="gui-bg-red gui-color-white gui-text gui-flex-shrink0"
							style="padding: 20rpx 20rpx;">重新发送</view>
						<view v-else class="gui-bg-gray gui-color-black gui-text gui-flex-shrink0"
							style="padding: 20rpx 20rpx;">{{time}}s</view>
					</view>

				</template>

				<!-- 利用 flex 布局 可以放置多个自定义按钮哦  -->
				<template v-slot:btns>
					<view class="gui-padding">
						<button type="default" @tap="comfirm" class="gui-button-mini  gui-bg-red gui-color-white">
							确认
						</button>
					</view>
				</template>
			</gui-modal>
		</template>
	</hyb-page>

</template>
<script>
	export default {
		data() {
			return {
				info: {},
				code: "",
				dw_flag: true,
				time: 0,
			}
		},
		computed: {
			base: () => {
				return uni.storage.get("base");
			}
		},

		async onShow() {
			if (this.$store.state.base.yg_weizhi_zd) {
				//直接判断是否禁用了小程序定位
				this.checkAuth()
			} else {
				//先判断师傅的经纬度为空的情况判断是否禁用了小程序定位
				this.getInfo()
			}
		},

		methods: {

			location() {
				uni.location.getLocation().then((location) => {
					if (location) {
						uni.gPost('yuangong/save', {
							latitude: location.latitude,
							longitude: location.longitude
						}).then(res => {
							uni.showToast({
								title: '更新成功',
								icon: 'none'
							})
						})
					} else {
						uni.showToast({
							title: '定位失败',
							icon: 'none'
						})
					}
				})
			},

			checkAuth() {
				console.log("000")
				let that = this;
				uni.getSetting({
					success: (res) => {
						console.log(res);
						var status = res.authSetting;
						if (!status['scope.userLocation'] && this.dw_flag) {
							this.dw_flag = false;
							// 如果授权信息中没有地理位置的授权，则需要弹窗提示用户需要授权地理信息
							uni.showModal({
									title: "是否授权当前位置",
									content: "未获取到您的位置信息，系统无法为您推送订单，请点确定进入授权位置入口。1.点击“位置信息”。2.选择“使用小程序时允许”。然后返回到此页面即可。",
									success: (tip) => {
										if (tip.confirm) {
											// 如果用户同意授权地理信息，则打开授权设置页面，判断用户的操作
											uni.openSetting({
												success: (data) => {
													// 如果用户授权了地理信息在，则提示授权成功
													if (data.authSetting[
															'scope.userLocation'] ===
														true) {
														uni.showToast({
															title: "授权成功",
															icon: "success",
															duration: 1000
														})

													}
												}
											})
										} else {
											uni.navigateBack()
										}
										that.getInfo()
									}
								}

							)

						}
					},
					fail: (res) => {
						uni.showToast({
							title: "调用授权窗口失败",
							icon: "none",
							duration: 1000
						})
					}
				})
			},


			async getInfo() {

				let location = '';
				// #ifdef MP
				// 授权成功后，然后再次chooseLocation获取信息
				location = await uni.location.getLocation();
				// #endif

				uni.gPost("yuangong/info", {
					location: location,
					is_rz: 1
				}).then((info) => {
					if (info) {
						if (info.y_styles == "待审核") {
							uni.showModal({
								title: this.$store.state.base.show_base.shifu_bie_ming + "提醒",
								content: "申请还在审核中，请稍候再来...",
								showCancel: false,
								success: (res) => {
									if (res.confirm) {
										uni.gPost("base/info").then((base) => {
											this.$store.commit("set_base", base);
											uni.redirectTo({
												url: this.$store.state.base
													.hyzx_luj
											})
										})
									}
								}
							})
						} else if (info.y_styles == "审核拒绝") {
							uni.showModal({
								title: "入驻提示",
								content: "审核未通过，原因：" + info.shenhe_jujue + '。是否重新申请？',
								success: (res) => {
									if (res.confirm) {
										uni.navigateTo({
											url: "/hyb_o2o/jishi/ruzhu/ruzhu"
										})
									} else {
										uni.redirectTo({
											url: this.$store.state.base.hyzx_luj
										})
									}
								}
							})
						} else {
							info.y_endtime = info.y_endtime.substring(0, 10);
							this.info = info;
							if (!info.longitude || this.$store.state.base.yg_weizhi_zd) this.checkAuth();
						}
					} else {
						if (!this.$store.state.base.show_base.shifu_bie_ming) this.$store.state.base.show_base
							.shifu_bie_ming = '师傅/商家';
						uni.showModal({
							title: "入驻提示",
							content: "您还不是" + this.$store.state.base.show_base.shifu_bie_ming +
								",是否现在入驻?",
							success: (res) => {
								if (res.confirm) {
									uni.navigateTo({
										url: "/hyb_o2o/jishi/ruzhu/ruzhu"
									})
								} else {
									uni.redirectTo({
										url: this.$store.state.base.hyzx_luj
									})
								}


								uni.gPost("base/info").then((base) => {
									this.$store.commit("set_base", base)
								})
							},

						})
					}
				})
			},

			bzj() {
				if (this.info.baozhengjin > 0) {
					var itm_a = ["充值", "提现"];
				} else {
					var itm_a = ["充值"];
				}
				uni.showActionSheet({
					itemList: itm_a,
					success: (res) => {
						if (res.tapIndex == 1) {
							uni.gPost("fadan/counts").then((counts) => {
								if (counts > 0) {
									uni.showModal({
										title: "提现",
										content: "您有订单在竞价中、服务中、待验收状态，不允许提现「接单保证金」，请完成订单，再来提现",
										confirmText: "查看订单",
										success: (res) => {
											if (res.confirm) {
												uni.navigateTo({
													url: "/hyb_o2o/inner/pages/fabu/list?tag=yg&t_y_id=" +
														this.info.y_id
												})
											}
										}
									})
								} else {
									// uni.navigateTo({
									// 	url: "/hyb_o2o/tixian/tixian?tag=yg_bzj"
									// })
								}
							})


						} else if (res.tapIndex == 0) {
							this.recharge();
						}
					}
				})
			},

			comfirm() {
				if (this.code.length != 4) {
					uni.showToast({
						title: "验证码错误!",
						icon: 'none'
					})
				} else {
					uni.gPost("yuangong/remove").then(() => {
						this.$refs.popup.close();
						uni.redirectTo({
							url: this.$store.state.base.hyzx_luj
						})
					})
				}
			},

			setting() {
				uni.showActionSheet({
					itemList: ["注销帐户"],
					success: (res) => {
						if (res.tapIndex == 0) {
							uni.showModal({
								title: "注销提醒",
								content: "注销后将消除所信信息，是否确认操作1?",
								success: (res) => {
									if (res.confirm) {
										if (this.$store.state.base.dx_config) {
											uni.gPost("yuangong/zx/sms").then(() => {
												this.time = 120;
												this.timer();
												this.$refs.popup.open();
											})
										} else {
											uni.gPost("yuangong/remove").then(() => {
												this.$refs.popup.close();
												uni.redirectTo({
													url: this.$store.state.base
														.hyzx_luj
												})
											})
										}

									}
								}
							})
						}
					}
				})
			},


			timer() {
				if (this.time > 0) {
					this.time--;
					setTimeout(() => {
						this.timer();
					}, 1000)
				}
			},

			recharge() {
				this.$refs.bzj.open();
			},
			ti_xian(f_id) {

				if (f_id) {
					// uni.navigateTo({
					// 	url: "/hyb_o2o/tixian/tixian?tag=fx&id=" + f_id
					// })
				} else {
					// uni.navigateTo({
					// 	url: "/hyb_o2o/tixian/tixian?tag=yg"
					// })
				}
			},

			jdChange(e) {
				uni.gPost("yuangong/save", {
					y_id: this.info.y_id,
					jd_tongzhi: e.detail.value ? 1 : 0
				}).then((res) => {
					uni.gJs.msg("操作成功!")
				})
			},
			to(url) {
				uni.gJs.navigate(url);
			},
			yg_huiyuan() {
				// uni.navigateTo({
				// 	url: "/hyb_o2o/xqdt/xqdt"
				// })
			},
			toInfo() {
				uni.gJs.navigate("/hyb_o2o/user/info/info");
			},

		}
	}
</script>
<style scoped>
	.gui-icons {
		font-size: 50rpx;
	}

	.gui-list-title-text {
		font-size: 32rpx;
	}

	.gui-ic-banquan {
		width: 100%;
		text-align: center;
		margin-top: 10rpx;
		font-size: 25rpx;
		color: #b3b3b3;
	}

	.gui-button {
		padding: 0 40rpx !important;
		height: 60rpx;
		padding: 0;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.gui-ic-image {
		width: 68rpx;
		height: 68rpx;
		margin-bottom: 10rpx;
	}

	.avatar-wrapper {
		background: none;
		padding: 0;
		border: none;
	}

	.avatar-wrapper::after {
		border: none;
	}
</style>